package com.luoye.sr.service.impl;

import com.luoye.sr.service.IHelloService;
import com.netflix.hystrix.contrib.javanica.annotation.HystrixCommand;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;

/**
 * Created by Administrator on 2018/5/31.
 */
@Service
public class HelloServiceImpl implements IHelloService{
    private static Logger logger= LoggerFactory.getLogger(HelloServiceImpl.class);

    @Autowired
    private RestTemplate restTemplate;

    @HystrixCommand(fallbackMethod = "hiError")
    public String say(String name) {
        String word=restTemplate.getForObject("http://SERVICE-HI/hi/say?name="+name,String.class);
        logger.info("the word is:"+word);
        return word;
    }
    public String hiError(String name) {
        return "hi,"+name+",sorry,error!";
    }
}
